<?php

	class Places extends Controller {

		function __construct(){
			parent::__construct();
		}

		function index() {
			echo 'day la trang tin tuc';
			$this->view->render('Page/Places');
		}
		
		public function NewPlace () {
			$this->view->render('Page/NewPlace');
		}
		


	function share_place_wifi (){

		$error 		 = array();
		$place_id 	 = false;
		$isset_wifi  = false;


		$PlaceName 	= $this->f->validate_input_text('/^.{2,20}+$/i',$_POST['PlaceName']);
		$address  	= $this->f->validate_input_text('/^.{2,20}+$/i',$_POST['address']);
		$steet  	= $this->f->validate_input_text('/^.{2,20}+$/i',$_POST['steet']);
		$city  		= $this->f->validate_input_text('/^.{2,20}+$/i',$_POST['city']);
		$wifiName  	= $this->f->validate_input_text('/^.{2,20}+$/i',$_POST['wifiName']);
		$password  	= $this->f->validate_input_text('/^.{2,20}+$/i',$_POST['password']);
		$pin  		= trim($_POST['pin']);

		$count = 0;

		if($PlaceName 	== false) $error[] = 'PlaceName';
		if($address 	== false) $error[] = 'address';
		if($steet 		== false) $error[] = 'steet';
		if($city 		== false) $error[] = 'city';
		if($wifiName 	== false) $error[] = 'wifiName';
		if($password 	== false) $error[] = 'password';

		if(empty($error))
		{

			$place_id = $this->model->insert_place($PlaceName,$address,$steet,$city,'sdf');
			if($place_id)
			{
				$isset_wifi = $this->model->insert_wifi($place_id,$wifiName,$password,$pin);
			}

			$error[] = $isset_wifi;
		}
		echo json_encode($error);
	}

	public function vote (){
		$_return = false;
		$id  = 0;
		if(isset($_POST['id_wifi']))
		{
			
			$id  		= trim($_POST['id_wifi']);
			$_return 	= $this->model->update_vote_wifi($id,true);
		}
		if($_return){
			echo json_encode($this->model->get_curen_wifi($id));
		}
		else { echo $_return;}
	}
	
	public function unvote (){
		
		$_return = false;
		if(isset($_POST['id_wifi']))
		{
			$id 		= trim($_POST['id_wifi']);
			$_return[] 	= $this->model->update_vote_wifi($id,false);
		}
		echo json_encode($_return);
	}
}
?>